<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ShopRole extends Model
{
    protected $table = 'shop_role';
    
    protected $guarded = [];
    
    public function setImgUrlAttribute($ImgUrl)
    {
        if (is_array($ImgUrl)) {
            $this->attributes['img_url'] = json_encode($ImgUrl);
        }
    }

    public function getImgUrlAttribute($ImgUrl)
    {
        return json_decode($ImgUrl, true);
    }

    public function shop()
    {
        return $this->belongsTo(Shop::class,'shop_id','id');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id');
    }

}
